<?php
class Place_Model_SaleUser extends Zend_Db_Table{
    
    protected $_name  = "sale_user";
    protected $_primary = "sale_user_id";
    
    public function init()
    {
        $normalUtils = new My_Utils_NormalUtils();
        $DB = $normalUtils->getNormalDb(1);
        $this->_db = $DB;
        parent::_setupDatabaseAdapter();
    }
        
    public function getAllSaleUser(){
        $normalUtils = new My_Utils_NormalUtils();
        $DB = $normalUtils->getNormalDb(1);
        $registry   = Zend_Registry::getInstance();
        $constant = $registry->constants;
        $USER_ACTIVE = $constant->USER_ACTIVE;
        
        $getUser = $DB  ->select()
                        ->from(array('u'=>'sale_user'), 
                                    array('sale_user_id', 'login_name', 'full_name', 'email'))
                        ->where("active = ?", $USER_ACTIVE);
        $userResult = $DB->fetchAll($getUser);
        return $userResult;
    }
    
    public function getSaleUserById($saleId){
        $normalUtils = new My_Utils_NormalUtils();
        $DB = $normalUtils->getNormalDb(1);
        $registry   = Zend_Registry::getInstance();
        $constant = $registry->constants;
        $USER_ACTIVE = $constant->USER_ACTIVE;
        
        $getUserQuery = $DB  ->select()
                        ->from(array('u'=>'sale_user'), 
                                    array('sale_user_id', 'login_name', 'full_name', 'email'))
                        ->where("sale_user_id = ?", $saleId);
        $saleUserResult = $DB->fetchAll($getUserQuery);
        $saleUser = $saleUserResult[0];
        return $saleUser;
    }

}
